<template>
  <el-input v-bind="$attrs" :class="prefixCls" :size="size" :value="state">
    <template #append>
      <CountButton :size="size" :count="count" :value="state" :beforeStartFunc="sendCodeApi" />
    </template>
    <template #[item]="data" v-for="item in Object.keys($slots).filter((k) => k !== 'append')">
      <slot :name="item" v-bind="data || {}"></slot>
    </template>
  </el-input>
</template>

<script lang="ts">
import { defineComponent, PropType } from 'vue'
import CountButton from './CountButton.vue'

export default defineComponent({
  name: 'CountdownInput',
  components: {
    CountButton
  },
  inheritAttrs: false,
  props: {
    value: { type: String },
    size: { type: String, validator: (v: string) => ['default', 'large', 'small'].includes(v) },
    count: { type: Number, default: 60 },
    sendCodeApi: {
      type: Function as PropType<() => Promise<boolean>>,
      default: null
    }
  },
  setup() {
    const prefixCls = 'countdown-input'

    return {
      prefixCls
    }
  }
})
</script>

<style scoped lang="scss"></style>
